package org.jgs1904.test.array;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @author: 默苍璃
 * @date: 2022-09-08 14:09
 */
public class Array {
    public static void main(String[] args) {

        // 创建数组
        int[] ints = new int[5];  //5
        int[] intss = new int[]{};  //0
        double[] doubles = new double[5];   //5
        boolean[] booleans = new boolean[3];    //3

        /**
         * 指定初始化的元素，这样就不必写出数组大小，而是由编译器自动推算数组大小
         */
        int[] ints1 = {1, 2};
        int[] ints2 = {1, 2};
        int[] ints3 = {};

        //默认值
        System.out.println(ints[4]);
        System.out.println(doubles[3]);
        System.out.println(booleans[2]);

        //数组大小
        System.out.println(ints.length);
        System.out.println(intss.length);
        System.out.println(doubles.length);
        System.out.println(booleans.length);
        System.out.println(ints1.length);
        System.out.println(ints2.length);
        System.out.println(ints3.length);
    }


    /**
     * Arrays.toString()
     */
    @Test
    public void test01() {
        int[] ns = {1, 1, 2, 3, 5, 8};
        System.out.println(Arrays.toString(ns));
    }


    /**
     * 二维数组
     */
    @Test
    public void test02() {
        int[][] ints = {
                {1, 2, 3, 4}
        };
        System.out.println(ints.length);
        System.out.println(ints[0].length);
        System.out.println(ints[0]);
        System.out.println(Arrays.toString(ints));
        System.out.println(Arrays.deepToString(ints));
        System.out.println(ints[0][0]);
        System.out.println("______________________分割线______________________");
        //循环
        for (int[] anInt : ints) {
            for (int i : anInt) {
                System.out.println(i);
            }
        }
    }


    /**
     * 三维数组
     */
    @Test
    public void test03() {
        int[][][] ns = {
                {
                        {1, 2, 3},
                        {4, 5, 6},
                        {7, 8, 9}
                },
                {
                        {10, 11},
                        {12, 13}
                },
                {
                        {14, 15, 16},
                        {17, 18}
                }
        };

        String deep = Arrays.deepToString(ns);
        System.out.println(deep);

    }


}
